var __extends =
    (this && this.__extends) ||
    (function () {
      var e = function (t, n) {
        return (e =
          Object.setPrototypeOf ||
          ({ __proto__: [] } instanceof Array &&
            function (e, t) {
              e.__proto__ = t;
            }) ||
          function (e, t) {
            for (var n in t)
              Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
          })(t, n);
      };
      return function (t, n) {
        function i() {
          this.constructor = t;
        }
        if ("function" != typeof n && null !== n)
          throw new TypeError(
            "Class extends value " + String(n) + " is not a constructor or null"
          );
        e(t, n),
          (t.prototype =
            null === n
              ? Object.create(n)
              : ((i.prototype = n.prototype), new i()));
      };
    })(),
  HeroConventionView = (function (e) {
    function t() {
      var t = e.call(this) || this;
      return (
        (t.isStartState = !1),
        (t.matchArray = []),
        (t.ownerGroup = -1),
        (t.rankNum = -1),
        (t.showStatus = 0),
        t.btn_conven_banck.on(Laya.Event.CLICK, t, t.onDidClickBackPreFn),
        t.btn_conven_joinZhanchang.on(
          Laya.Event.CLICK,
          t,
          t.onDidClickJoinAction
        ),
        t.btn_now_huangjun.on(Laya.Event.CLICK, t, t.onBtnClickConvenFn),
        t.btn_now_panjun.on(Laya.Event.CLICK, t, t.onBtnClickConvenFn),
        t.btn_defense_huangjun.on(Laya.Event.CLICK, t, t.onBtnClickConvenFn),
        t.btn_defense_panjun.on(Laya.Event.CLICK, t, t.onBtnClickConvenFn),
        t.btn_guizeshuoming.on(Laya.Event.CLICK, t, t.OnDidClickGZSMAction),
        t.btn_jianglingshuoming.on(Laya.Event.CLICK, t, t.OnDidClickJLSMAction),
        (t.list_last_item.vScrollBarSkin = ""),
        (t.list_defense_item.vScrollBarSkin = ""),
        (t.list_defense_item.selectEnable = !0),
        t.list_defense_item.on(Laya.Event.CLICK, t, t.onDefenseListClickFn),
        (t.list_defense_item.renderHandler = new Laya.Handler(
          t,
          t.updateMatchItemRender
        )),
        WebSocketService.addListener({
          caller: t,
          code: 1523,
          method: t.onLoadConventionViewData,
        }),
        WebSocketService.addListener({
          caller: t,
          code: 1532,
          method: t.onLoadSelectZhenYingData,
        }),
        WebSocketService.addListener({
          caller: t,
          code: 1536,
          method: t.onLoadLaunchFightData,
        }),
        WebSocketService.addListener({
          caller: t,
          code: 1535,
          method: t.onLoadListItemData,
        }),
        WebSocketService.addListener({
          caller: t,
          code: 2074,
          method: t.onLoadPreData,
        }),
        WebSocketService.addListener({
          caller: t,
          code: 1533,
          method: t.onLoadNowData,
        }),
        t
      );
    }
    return (
      __extends(t, e),
      (t.showHeroConvenView = function () {
        return (
          null == this.heroConvenV && (this.heroConvenV = new t()),
          WebSocketService.send({ c: 1523 }),
          (this.heroConvenV.btn_conven_joinZhanchang.visible = !0),
          (this.heroConvenV.label_conven_paiming.visible = !1),
          (this.heroConvenV.label_conven_zhenying.text = ""),
          (this.heroConvenV.last_box.visible = !1),
          (this.heroConvenV.now_box.visible = !1),
          (this.heroConvenV.defense_box.visible = !1),
          (this.heroConvenV.ownerGroup = -1),
          this.heroConvenV
        );
      }),
      (t.prototype.changeBoxShow = function (e) {
        (this.showStatus = e),
          1 == e
            ? ((this.label_conven_shangjiezhuangkuang.text = "上届战况"),
              (this.label_con_huangjunNum.text = "(0)"),
              (this.label_con_panjunNum.text = "(0)"),
              (this.last_box.visible = !0),
              (this.now_box.visible = !1),
              (this.defense_box.visible = !1))
            : 2 == e
            ? ((this.label_conven_shangjiezhuangkuang.text = "当前战况"),
              (this.last_box.visible = !1),
              (this.now_box.visible = !0),
              (this.defense_box.visible = !1))
            : 3 == e &&
              ((this.label_conven_shangjiezhuangkuang.text = "阵营防卫"),
              (this.last_box.visible = !1),
              (this.now_box.visible = !1),
              (this.defense_box.visible = !0));
      }),
      (t.prototype.onLoadConventionViewData = function (e) {
        0 == e.code
          ? ((this.curJson = e.data),
            (this.rankNum = e.data.id),
            (this.timeDiff = e.data.t),
            Laya.timer.loop(1e3, this, this.timerCountDownConventionFn),
            1 == e.data.s && 3 != this.showStatus
              ? (this.startGongFangZhan(!0),
                (this.btn_now_huangjun.label = "皇军(" + e.data.cj + "胜)"),
                (this.btn_now_panjun.label = "联军(" + e.data.lj + "胜)"),
                WebSocketService.send({
                  c: 1533,
                  d: { id: e.data.id, pageNum: 0 },
                }),
                "-1" == this.curJson.r
                  ? (this.label_conven_paiming.text = "您当前没有排名")
                  : (this.label_conven_paiming.text =
                      "您当前的排名" +
                      this.curJson.r +
                      " 共" +
                      this.curJson.n +
                      "积分"))
              : 0 == e.data.s &&
                (this.startGongFangZhan(!1),
                (this.label_con_huangjunNum.text = "(" + e.data.cj + "胜)"),
                (this.label_con_panjunNum.text = "(" + e.data.lj + "胜)"),
                0 == this.list_last_item.length &&
                  WebSocketService.send({
                    c: 2074,
                    d: { id: e.data.id, pageNum: 0 },
                  })))
          : ToastView.toastView(e.msg);
      }),
      (t.prototype.startGongFangZhan = function (e) {
        e
          ? ((this.isStartState = !0),
            this.changeBoxShow(2),
            (this.btn_conven_joinZhanchang.visible = !0))
          : ((this.isStartState = !1),
            this.changeBoxShow(1),
            (this.btn_conven_joinZhanchang.visible = !1),
            (this.label_conven_zhenying.text = ""),
            (this.label_conven_paiming.text = ""));
      }),
      (t.prototype.onLoadListItemData = function (e) {
        if (0 == e.code) {
          if (this.currentPage >= 1) {
            if (0 == e.list.length) return void this.currentPage--;
            for (var t = 0; t < e.list.length; t++) {
              var n = e.list[t];
              this.matchArray.push(n);
            }
          } else this.matchArray = e.list;
          (this.dataSource = []),
            (this.isloading = !1),
            (this.list_defense_item.visible = !0);
          for (var i = 0; i < this.matchArray.length; i++) {
            var o = this.matchArray[i],
              a = {
                label_conven_index: { text: o.n + " 已获得积分" + o.r },
                label_conven_name: { text: "" },
                btn_conven_jingong: { label: "进攻" },
                id: o.id,
              };
            this.dataSource.push(a);
          }
          this.list_defense_item.dataSource = this.dataSource;
        } else ToastView.toastView(e.msg);
      }),
      (t.prototype.onLoadPreData = function (e) {
        0 != e.code && ToastView.toastView(e.msg);
        if (this.currentPage >= 1) {
          if (0 == e.list.length) return void this.currentPage--;
          for (var t = 0; t < e.list.length; t++) {
            var n = e.list[t];
            this.matchArray.push(n);
          }
        } else this.matchArray = e.list;
        for (var i = [], o = 0; o < this.matchArray.length; o++) {
          var a = this.matchArray[o],
            s = {
              label_conven_index: { text: a.r },
              label_conven_name: { text: a.n + "   积分" + a.s },
            };
          i.push(s);
        }
        this.list_last_item.dataSource = i;
      }),
      (t.prototype.onLoadNowData = function (e) {
        0 != e.code && ToastView.toastView(e.msg);
        for (var t = e.list, n = [], i = 0; i < t.length; i++) {
          var o = t[i],
            a = {
              label_conven_index: { text: o.r },
              label_conven_name: { text: o.n + "   积分" + o.s },
            };
          n.push(a);
        }
        this.list_now_item.dataSource = n;
      }),
      (t.prototype.onDefenseListClickFn = function (e) {
        if ("" != e.target.name && "btn_conven_jingong" == e.target.name) {
          var t = this.list_defense_item.selectedItem;
          WebSocketService.send({ c: 1536, d: { id: t.id } });
        }
      }),
      (t.prototype.updateMatchItemRender = function (e, t) {
        if (!(t > this.matchArray.length)) {
          e.getChildByName("label_conven_index"),
            e.getChildByName("label_conven_name");
          var n = e.getChildByName("btn_conven_jingong");
          this.btn_defense_huangjun.selected && 2 == this.ownerGroup
            ? (n.visible = !0)
            : this.btn_defense_panjun.selected && 1 == this.ownerGroup
            ? (n.visible = !0)
            : (n.visible = !1);
        }
      }),
      (t.prototype.onLoadSelectZhenYingData = function (e) {
        0 == e.code
          ? (1 == e.data.side
              ? ((this.label_conven_zhenying.text =
                  "当前您扮演 " + e.data.n + " 处于 皇军 阵营"),
                (this.ownerGroup = 1),
                WebSocketService.send({ c: 1535, d: { s: 2, pageNum: 0 } }),
                (this.btn_defense_panjun.selected = !0),
                (this.btn_defense_huangjun.selected = !1))
              : 2 == e.data.side &&
                ((this.label_conven_zhenying.text =
                  "当前您扮演 " + e.data.n + " 处于 叛军 阵营"),
                (this.ownerGroup = 2),
                WebSocketService.send({ c: 1535, d: { s: 1, pageNum: 0 } }),
                (this.btn_defense_huangjun.selected = !0),
                (this.btn_defense_panjun.selected = !1)),
            (this.btn_conven_joinZhanchang.visible = !1),
            (this.label_conven_paiming.visible = !0),
            this.changeBoxShow(3))
          : ToastView.toastView(e.msg);
      }),
      (t.prototype.onLoadLaunchFightData = function (e) {
        e.code, ToastView.toastView(e.msg);
      }),
      (t.prototype.onDidClickJoinAction = function (e) {
        WebSocketService.send({ c: 1532 });
      }),
      (t.prototype.onBtnClickConvenFn = function (e) {
        "now0" == e.target.name
          ? ((this.btn_now_huangjun.selected = !0),
            (this.btn_now_panjun.selected = !1),
            WebSocketService.send({ c: 1533, d: { s: 1, pageNum: 0 } }))
          : "now1" == e.target.name &&
            ((this.btn_now_huangjun.selected = !1),
            (this.btn_now_panjun.selected = !0),
            WebSocketService.send({ c: 1533, d: { s: 2, pageNum: 0 } })),
          "defense0" == e.target.name
            ? ((this.btn_defense_huangjun.selected = !0),
              (this.btn_defense_panjun.selected = !1),
              WebSocketService.send({ c: 1535, d: { s: 1, pageNum: 0 } }))
            : "defense1" == e.target.name &&
              ((this.btn_defense_huangjun.selected = !1),
              (this.btn_defense_panjun.selected = !0),
              WebSocketService.send({ c: 1535, d: { s: 2, pageNum: 0 } }));
      }),
      (t.prototype.updateConventionView = function (e) {
        1 == e
          ? ((this.label_conven_shangjiezhuangkuang.y = 117),
            (this.btn_now_huangjun.y = 223),
            (this.btn_now_panjun.y = 223))
          : 2 == e &&
            ((this.btn_now_huangjun.y = 223), (this.btn_now_panjun.y = 223));
      }),
      (t.prototype.timerCountDownConventionFn = function () {
        this.timeDiff--;
        var e = 0,
          t = 0,
          n = 0,
          i = 0;
        (e = Math.floor(this.timeDiff / 86400)),
          (t = Math.floor((this.timeDiff % 86400) / 3600)),
          (n = Math.floor((this.timeDiff % 3600) / 60)),
          (i = Math.floor(this.timeDiff % 60)),
          e <= 0 && t <= 0 && n <= 0 && i <= 1
            ? (Laya.timer.clear(this, this.timerCountDownConventionFn),
              (this.label_conven_timedown.text = "请稍等..."),
              WebSocketService.send({ c: 1523 }))
            : i % 25 == 0
            ? (this.isStartState &&
                (Laya.timer.clear(this, this.timerCountDownConventionFn),
                WebSocketService.send({ c: 1523, d: null }),
                WebSocketService.send({ c: 1553 }),
                this.isStartState &&
                  (1 == this.btn_defense_huangjun.selected
                    ? WebSocketService.send({
                        c: 1535,
                        d: { s: 1, pageNum: 0 },
                      })
                    : WebSocketService.send({
                        c: 1535,
                        d: { s: 2, pageNum: 0 },
                      }))),
              (this.label_conven_timedown.text = this.dealTimeDataWithParams(
                e,
                t,
                n,
                i
              )))
            : (this.label_conven_timedown.text = this.dealTimeDataWithParams(
                e,
                t,
                n,
                i
              ));
      }),
      (t.prototype.dealTimeDataWithParams = function (e, t, n, i) {
        var o = "0秒";
        e > 0
          ? (o = e + "天" + t + "小时" + n + "分" + i + "秒")
          : t > 0
          ? (o = t + "小时" + n + "分" + i + "秒")
          : n > 0
          ? (o = n + "分" + i + "秒")
          : i > 0 && (o = i + "秒");
        return this.isStartState ? o + "后结束战斗" : "距离战斗打响还有" + o;
      }),
      (t.prototype.onLoadMoreData = function (e) {
        var t = e / this.list_defense_item.scrollBar.max,
          n = new Date();
        if (!(n.getTime() - this.spaceTime >= 3e3))
          return 1 == t && 0 == this.isloading
            ? ((this.isloading = !0),
              (this.currentPage = 2),
              1 == this.ownerGroup || -1 == this.ownerGroup
                ? WebSocketService.send({
                    c: 1535,
                    d: { s: 1, pageNum: this.currentPage },
                  })
                : 2 == this.ownerGroup &&
                  WebSocketService.send({
                    c: 1535,
                    d: { s: 2, pageNum: this.currentPage },
                  }),
              void (this.spaceTime = n.getTime()))
            : void 0;
      }),
      (t.prototype.OnDidClickGZSMAction = function () {
        var e = RulesView.showCaslRuleView("gongfanzhanGZSM");
        (e.y = 0), Laya.stage.addChild(e);
      }),
      (t.prototype.OnDidClickJLSMAction = function () {
        var e = RulesView.showCaslRuleView("gongfanzhanJNSM");
        (e.y = 0), Laya.stage.addChild(e);
      }),
      (t.prototype.onDidClickBackPreFn = function () {
        Laya.timer.clear(this, this.timerCountDownConventionFn),
          Laya.timer.clearAll(this),
          (this.showStatus = 0),
          this.removeSelf();
      }),
      t
    );
  })(ui.ChallengeBattle.HeroConventionViewUI);
